<template>
  <!-- 复核管理列表 -->
  <base-breadcrumb>
    <searchData :searchData="searchArr" @search="search"></searchData>
    <a-card>
      <list-table
        ref="table"
        class="export-table"
        :columns="columns"
        :request="loadData"
        :isEportIndex="true"
        :start-index="0"
        :export-config="{ use: true, select: '', all: '' }"
        :statisticsConfig="{ use: true, temp: statisticsTemp }"
        :export-permission="{ select: 'tm_033_exp_02', all: 'tm_033_exp_02' }"
      >
        <template slot="operation" slot-scope="text, record">
          <MoreButton>
            <template>
            <a v-btnPermission="'tm_033_loo_04'" @click="handleManage('look', record)">查看</a>
            <a v-btnPermission="'tm_033_aga_03'" v-if="record.reviewConclusion === 1"  @click="handleManage('edit', record)">重新复核</a>
            </template>
          </MoreButton>
        </template>
        <!-- 新增 -->
        <a-button slot="prefix" v-btnPermission="'tm_033_add_01'" class="mb12"  icon="plus" type="primary" @click="handleManage('add')"> 新增 </a-button>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
import BasePage from '@/views/basePage' // 基础配置
import { getPageTechnicalReviewManagement, insertSelectiveaginCount } from '@/api/technical/technicalReview'

import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import { getReviewCheckProjectAll } from '@/api/technical/reviewContent'
const columns = [
  {
    title: '序号',
    width: 80,
    dataIndex: 'index',
    customRender() {
      return arguments[2] + 1
    }
  },
  {
    title: '所属分公司',
    dataIndex: 'branchComName'
  },
  {
    title: '所属项目',
    dataIndex: 'projectName'
  },

  {
    title: '复核部位',
    dataIndex: 'checkParts',
    ellipsis: true
  },
  {
    title: '复核项目',
    dataIndex: 'checkProjectName',
    ellipsis: true
  },
  {
    title: '复核内容',
    dataIndex: 'checkContentName',
    ellipsis: true
  },
  {
    title: '方案名称',
    dataIndex: 'constructionProgramName',
    ellipsis: true
  },
  {
    title: '复核类型',
    dataIndex: 'reviewTypeName',
    ellipsis: true
  },
  {
    title: '复核人',
    dataIndex: 'practicalParticipantName',
    ellipsis: true
  },
  {
    title: '复核结论',
    dataIndex: 'reviewConclusionName'
  },
  {
    title: '复核完成时间',
    dataIndex: 'reviewCompletionTime'
  },

  {
    title: '填报时间',
    dataIndex: 'fillTime'
  },
  // {
  //   title: '计划完成时间',
  //   dataIndex: 'reviewCompletionTime',
  // },
  // {
  //   title: '填报时间',
  //   dataIndex: 'reviewCompletionTime',
  // },
  {
    title: '操作',
    dataIndex: 'operation',
    width: '80px',
    scopedSlots: { customRender: 'operation' }
  }
]

export default {
  name: 'a' + Date.now(),
  extends: new BasePage(),
  data() {
    this.columns = columns
    return {
      queryParam: { isApp: 1 },
      from: {},
      loadData: async (parameter) => {
        const requestParameters = Object.assign({}, parameter, { query: this.queryParam })
        insertSelectiveaginCount(requestParameters).then((resCount) => {
          if (resCount.data) {
            this.from = resCount.data
          }
        })
        return getPageTechnicalReviewManagement(requestParameters).then((res) => {
          if(Array.isArray(res.data)){
            res.data.map(el=>{
              el.practicalParticipantName = typeof(el.practicalParticipantName) === 'string'? el.practicalParticipantName.split(',').map(el=>el?.trim()?.split(' ')[0]).join() : ''
              return el
            })
          }
          return res
        })
      }
    }
  },
  computed: {
    searchArr() {
      return [
        // {
        //   name: '所属分公司',
        //   valueKey: 'branchComId',
        //   type: SelectSubCompany
        // },
        {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect
        },
        // {
        //   name: '所属项目',
        //   keyValue: 'branchComId',
        //   valueKey: 'projectId',
        //   type: SelectProject
        // },
        {
          name: '复核项目',
          value: 'checkProjectName',
          type: 'input'
        },
        {
          name: '复核内容',
          value: 'reviewContent',
          type: 'input'
        },
        {
          name: '复核类型',
          valueKey: 'reviewType',
          value: 'reviewType',
          type: 'select',
          data: [
            { label: '计划内', value: 0 },
            { label: '计划外', value: 1 },
          ]
        },
        {
          name: '复核人',
          value: 'practicalParticipantName',
          type: 'input'
        },
        {
          name: '复核完成时间',
          type: 'dateRange',
          value: 'reviewCompletionTime',
          attr: {
            rangeFormat: ['startTime', 'endTime']
          }
        },
        {
          name: '方案名称',
          value: 'constructionProgramName',
          type: 'input'
        },
        {
          name: '复核结论',
          valueKey: 'reviewType',
          value: 'reviewConclusion',
          type: 'select',
          data: [
            { label: '通过', value: 0 },
            { label: '不通过', value: 1 }
          ]
        },
        {
          name: '计划完成时间',
          type: 'dateRange',
          value: 'plannedCompletionTime',
          attr: {
            rangeFormat: ['planStartTime', 'planEndTime']
          }
        },
        {
          name: '填报时间',
          type: 'dateRange',
          value: 'fillTime',
          attr: {
            rangeFormat: ['fillStartTime', 'fillEndTime']
          }
        }
      ]
    }
  },
  methods: {
    /**
     * 统计
     */
    statisticsTemp() {
      return (
        <span>
          <span>
            计划内-计划复核数量:<a>{this.from.insideNum}&emsp;</a>
          </span>
          <span>
            实际复核数量:<a>{this.from.actInsideNum}&emsp;</a>
          </span>
          <span>
            复核率：<a>{this.from.review}&emsp;</a>
          </span>
          <span>
            复核通过次数：<a>{this.from.reviewPassNum}&emsp;</a>
          </span>
          <span>
            复核不通过次数:<a>{this.from.reviewRejectNum}&emsp;</a>
          </span>
          <span>
            计划外-复核数量:<a>{this.from.outNum}&emsp;</a>
          </span>
          <span>
            复核通过次数:<a>{this.from.outReviewPassNum}&emsp;</a>
          </span>
          <span>
            复核不通过次数:<a>{this.from.outReviewRejectNum}&emsp;</a>
          </span>
        </span>
      )
    },
    //搜索
    search(value) {
      value && (this.queryParam = { ...value, isApp: 1 })
      this.$refs.table.refresh(true)
    },
    //操作栏
    handleManage(pageType, record = {}) {
      const commonHandler = () => {
        this.$router.push({
          name: 'viewReview',
          query: {
            id: record.id || '',
            pageType,
            typeReview: record.reviewType || ''
          }
        })
      }
      const typeMap = {
        add: commonHandler,
        edit: commonHandler,
        look: commonHandler
      }
      typeMap[pageType] && typeMap[pageType]()
      // let query = {}
      // if (record && record.id) {
      //   query = {
      //     id: record.id,
      //     typeReview: record.reviewType
      //   }
      // }
      // this.$router.push({
      //   name: 'viewReview',
      //   query
      // })
    }
  }
}
</script>


